/* Copyright (C) 2010 Fredrique Samuels, fredriquesamuels@gmail.com 

 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "timestamp.h"

namespace tri{


TTimeStamp::TTimeStamp():_sec(TTimeStamp::now())
{
}

TTimeStamp::TTimeStamp(time_t sec):_sec(sec)
{
}

TTimeStamp::~TTimeStamp()
{
}

void TTimeStamp::setTimeInSeconds(time_t t){
    _sec = t;
}

time_t TTimeStamp::get(){
    return _sec;
}

time_t TTimeStamp::diff(TTimeStamp& t){
    return get() - t.get();
}

time_t TTimeStamp::now(){
    return time(NULL);
}

float  TTimeStamp::min2hour(float min){
    return min/60.0;
}

float  TTimeStamp::hour2min(float hours){
    return hours*60.0;
}
float  TTimeStamp::min2sec(float min){
    return min*60.0;
}
float  TTimeStamp::sec2min(float sec){
    return sec/60.0;
}
    
float  TTimeStamp::day2hour(float d){
    return d*24.0;
}
float  TTimeStamp::hour2day(float h){
    return h/24.0;
}

bool TTimeStamp::operator==( TTimeStamp& t){
    return this->get()==t.get();
}

}

std::ostream &operator<<(std::ostream& out,tri::TTimeStamp& h){
    time_t t = h.get();
    out<<ctime(&t);
    return out;
}

